package com.ruoyi.recipes.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.recipes.domain.CategoryTop;
import com.ruoyi.recipes.service.ICategoryTopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 一级菜谱分类Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@Controller("recipeCategoryTopController")
@RequestMapping("/recipes/category_top")
public class CategoryTopController extends BaseController
{
    @Autowired
    private ICategoryTopService categoryTopService;

    /**
     * 查询一级菜谱分类列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:category_top:list')")
    @GetMapping("/list")
    public TableDataInfo list(CategoryTop categoryTop)
    {
        startPage();
        List<CategoryTop> list = categoryTopService.selectCategoryTopList(categoryTop);
        return getDataTable(list);
    }

    /**
     * 导出一级菜谱分类列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:category_top:export')")
    @Log(title = "一级菜谱分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CategoryTop categoryTop)
    {
        List<CategoryTop> list = categoryTopService.selectCategoryTopList(categoryTop);
        ExcelUtil<CategoryTop> util = new ExcelUtil<CategoryTop>(CategoryTop.class);
        util.exportExcel(response, list, "一级菜谱分类数据");
    }

    /**
     * 获取一级菜谱分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('recipes:category_top:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(categoryTopService.selectCategoryTopById(id));
    }

    /**
     * 新增一级菜谱分类
     */
    @PreAuthorize("@ss.hasPermi('recipes:category_top:add')")
    @Log(title = "一级菜谱分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryTop categoryTop)
    {
        return toAjax(categoryTopService.insertCategoryTop(categoryTop));
    }

    /**
     * 修改一级菜谱分类
     */
    @PreAuthorize("@ss.hasPermi('recipes:category_top:edit')")
    @Log(title = "一级菜谱分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryTop categoryTop)
    {
        return toAjax(categoryTopService.updateCategoryTop(categoryTop));
    }

    /**
     * 删除一级菜谱分类
     */
    @PreAuthorize("@ss.hasPermi('recipes:category_top:remove')")
    @Log(title = "一级菜谱分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(categoryTopService.deleteCategoryTopByIds(ids));
    }
}
